<div class="register-wrap clearfix">
  <h4><{t}>取回密码第二步：验证身份<{/t}></h4>
  <!--p class="intro">
    <{t}>说明：当你填写邮箱并提交后，密码会自动发到您注册的邮箱里面，请及时收邮件，取回密码！<{/t}>
  </p-->
  <div class="form password-return">
    <form id="recoverForm" name="FORM_TPL_FORGETQUESTION" method="post" action=<{link app=b2c ctl="site_passport" act="sendPSW"}>>
      <ul>
        <li>
          <label><{t}>请选择验证身份方式：<{/t}></label>
          <select id="verify_way" name="verify_way" vtype="required" onchange="getVerifyWay(this);">
            <{foreach from=$verifyWay item=option name="option"}>
              <option value="<{$option}>">
                <{if $option == 'mobile'}>已验证手机<{else}>邮箱<{/if}>
              </option>
            <{/foreach}>
          </select>
        </li>
        <li>
          <label><{t}>用户名：<{/t}></label>
          <{$data.hidden_name}><input type=hidden name=uname value="<{$data.login_name}>" />
        </li>
        <div id="verify_email" style="">
          <li>
            <label><{t}>邮箱：<{/t}></label>
            <{$data.contact.hidden_email}>
            <input name="contact[email]" type="hidden" value="<{$data.contact.email}>" />
          </li>
        </div>
        <div id="verify_mobile" style="display:none">
          <li>
            <label><{t}>已验证手机：<{/t}></label>
            <{$data.contact.phone.hidden_mobile}>
            <input id="reg_mobile" name="contact[phone][mobile]" type="hidden" value="<{$data.contact.phone.mobile}>" />
          </li>
          <li id="mobileCode">
            <label class="login-k"><i>*</i><{t}>短信验证码：<{/t}></label>
            <{input vtype="number&&required" size="6" maxlength="6" class="" style="width:60px;padding:6px 0px 6px 14px;" name="mobileverifycode" id="mobileverifycode"}>
            <div class="getmobilecode">
              <button class="sendMobileCode" type="button" onclick="getRecoverMobileCode();">获取短信验证码</button>
              <div id="mobile_success">
                <span id="cut_time" style="display: none;">剩余时间<span class="second_red">58</span>秒</span>
              </div>
            </div>
          </li>
        </div>
        <li id="button-li" class="button-li">
          <!--{button id="submit_btn" type="submit"  class="common-btn" rel="_request" label=$___b2c="提交"|t:'b2c'}-->
        </li>
      </ul>
    </form>
  </div>
</div>

<script>
    (function(){
        var verify_way = $('verify_way').value;
        if(verify_way == 'mobile'){
            $('verify_email').setStyle('display','none');
            $('verify_mobile').setStyle('display','');
            $('button-li').setHTML('<{button id="submit_btn" type="submit"  class="common-btn" label=$___b2c="下一步"|t:"b2c"}>');
        }else{
            $('verify_email').setStyle('display','');
            $('verify_mobile').setStyle('display','none');
            $('button-li').setHTML('<{button id="submit_btn" type="submit"  class="common-btn" label=$___b2c="发送验证邮件"|t:"b2c"}>');
        }
    })();

    function getVerifyWay(way){
        if(way.value == 'email'){
            $('verify_email').setStyle('display','');
            $('verify_mobile').setStyle('display','none');
            $('button-li').setHTML('<{button id="submit_btn" type="submit"  class="common-btn" label=$___b2c="发送验证邮件"|t:"b2c"}>');
        }else{
            $('verify_email').setStyle('display','none');
            $('verify_mobile').setStyle('display','');
            $('button-li').setHTML('<{button id="submit_btn" type="submit"  class="common-btn" label=$___b2c="下一步"|t:"b2c"}>');
        }
    }

    //获取手机短信验证码
    function getRecoverMobileCode(){
        var mobile = $('reg_mobile').value;
        var obj = $$('.getmobilecode button');
        new Request({
            url:'<{link app=b2c ctl=site_passport act=getRecoverMobileCode}>',
            onComplete:function(response){
                if (response==1) {
                    obj.set('html', '验证码已发送');
                    obj.set('disabled', true);
                    hideInfo();
                    try{timeDown.init(120,obj)}catch(e){};
                }else{
                    displayInfo();
                    obj.set('html', '获取手机验证码');
                    obj.set('disabled', false);
                }
            },
            data:'contact[phone][mobile]='+mobile
        }).send();
    }

    function displayInfo(){
        $('mobile_success').hide();
    }

    function hideInfo(){
        $('mobile_success').show();
    }

    (function() {
        var timeDown = this.timeDown = {
            init : function(time,dom){
                var timeDiff = [time];
                this.s = this.calcTime.periodical(1000,this,{
                    time:timeDiff,
                    dom:dom
                });
            },
            addZero : function(timeDiff){
                for(var i=0;i<timeDiff.length;i++){
                    if(timeDiff[i].toString().length<2){
                        timeDiff[i] = "0" + timeDiff[i].toString();
                        return timeDiff;
                    }
                }
            },
            formatToInt : function(timeDiff){
                for(var i=0;i<timeDiff.length;i++){
                    parseInt(timeDiff[i]);
                }
                return timeDiff;
            },
            judgeTime : function(timeDiff){
                if(timeDiff[0]==0){
                    $clear(this.s);
                    return;
                }
            },
            calcTime : function (obj){
                if(!obj.dom) return;
                var _timeDiff = obj.time;
                this.formatToInt(_timeDiff);
                _timeDiff[0]--;
                this.judgeTime(_timeDiff);
                this.addZero(_timeDiff);
                var dom = obj.dom;
                if(_timeDiff[0] > 0 && dom){
                    $$('.second_red').set('html', _timeDiff[0]);
                    $('cut_time').show();
                }else{
                    dom.set('disabled', false);
                    dom.set('html', '再次获取验证码');
                    $('cut_time').hide();
                }
            }
        };
    })();
</script>